 //************************************************************************
 // AccountCollection.java                  Author:20172323wyh
 //************************************************************************
 public class AccountCollection {
    private Account[] collection;
    private int count;

    public AccountCollection()
    {
        collection = new Account[30];
        count = 0;
    }

    //---------------------------------------------------------------
    //    Adds a account to the collection.
    //---------------------------------------------------------------
    public void addAccount(String owner, long account, double initial)
    {
        if (count > 30)
            increaseSize();
        else
        {
            collection[count] = new Account(owner, account, initial);
            System.out.println("新账户编号: " + count +
                    "\n户主: " + owner +
                    "\n账号: " + account +
                    "\n余额: " + initial);
            count++;
        }
    }

    //---------------------------------------------------------------
    //    Deposits money into the account.
    //---------------------------------------------------------------
    public String putMoney(double amount, int number)
    {
        if (collection[number] != null)
        {
            collection[number].deposit(amount);
            return "存入： " + amount + " 存入账户： " + number + "\n当前余额: " + collection[number].getBalance() ;
        }
        else
            return "错误";
    }

    //---------------------------------------------------------------
    //    Withdraws money from the account.
    //---------------------------------------------------------------
    public String getMoney(double amount, double fee, int number)
    {
        if (collection[number] != null)
        {
            collection[number].withdraw(amount, fee);
            return "取出： " + amount + " 取出账户： " + number +
                    "\n手续费： " + fee + "\n当前余额: " + collection[number].getBalance() ;
        }
        else
            return "错误";
    }

    //---------------------------------------------------------------
    //    Adds interest to every accounts.
    //---------------------------------------------------------------
    public String addInterest()
    {
        for (int acctIndex = 0; acctIndex <= count; acctIndex++)
        {
            if (collection[acctIndex] != null)
            {
                collection[acctIndex].addInterest();
            }
            else
                break;
        }
        return "增加利息\n";
    }


    //---------------------------------------------------------------
    //    Returns a report describing the Account collection.
    //---------------------------------------------------------------
    public String toString()
    {
        int index = count;
        String report = "账户编号: " + count + "\n账户详情：\n";

        for (int acctIndex = 0; acctIndex <= count; acctIndex++)
        {
            if (collection[acctIndex] != null)
                report += collection[acctIndex].toString() + "\n";
            else
                break;
        }

        return report;
    }
    private void increaseSize()
    {
        Account[] temp = new Account[collection.length * 2];

        for (int x = 0; x < collection.length; x++)
            temp[x] = collection[x];

        collection = temp;
    }



}
